package com.lebang.controller.api.donwn;

import com.lebang.entity.RequestHeaders;
import com.lebang.service.sys.AppMainBannerService;
import com.lebang.service.sys.DictService;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: hwq
 * @Date: 2020/3/25 18:20
 * @Version 1.0
 */
@RestController
@RequestMapping("/app/open")
public class OpenController {
    @Autowired
    private DictService dictService;
    @Autowired
    private AppMainBannerService appMainBannerService;


    @GetMapping("/check/{key}")
    public JsonData lunbo(HttpServletRequest request, @PathVariable("key") String key) {

        if (dictService.selectIntByKeyName(key) > 0) {
            return Callback.success("success", "查询成功");
        } else {
            return Callback.fail("success", "查询成功");
        }

    }
    @GetMapping("/get/{key}")
    public JsonData get(HttpServletRequest request, @PathVariable("key") String key) {
        return Callback.success("success", "查询成功", dictService.selectByKeyName(key).getKeyvalue());
    }

    /**
     * 根据广告位获取数据源
     *
     * @param request
     * @return
     */
    @ApiParam("获取开屏轮播")
    @GetMapping("/bannermain")
    public JsonData getByAll(HttpServletRequest request) {
        RequestHeaders header = new RequestHeaders(request);
        return Callback.success("200", "查询成功", appMainBannerService.getKeyByCount(header.getImei()));
    }
}
